import $store from '@/store/index.js';
import { checkUpdate } from "@/components/app-update/js/app-update-check.js";
export default {
	//默认自动更新
	async appUpdate(type = 0,requestError = true){
		try{
			let varinfores = await this.getVersionInfo(requestError)
			console.log(varinfores);
			if(varinfores){
				let res = await checkUpdate(varinfores, type)///检查更新
				if (res.msg && type == 1) {
				 	uni.showToast({
				 		title:res.msg,
				 		icon:'none'
				 	})
				}
			}
		}catch(e){
			//TODO handle the exception
		}
	},
	
	/* 版本更新 */
	async getVersionInfo(requestError) {
		try{
			let device_os = uni.$u.os()
			let res = await uni.$api.common.getVersionInfo({
				plat_code:uni.$config.plat_code,
				device_os,
			},requestError)
			if(res){
				return res.data
			}else{
				return false
			}
		}catch(e){
			throw e;
		}
	},
}